package com.eugene.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eugene.element.FnCalendar;
import com.eugene.element.StockIndex;
import com.eugene.util.HibernateUtil;

public class StockIndexDAO {
	private final static Logger logger = LoggerFactory.getLogger(StockIndexDAO.class);	
	
	public static List<StockIndex> getStockIndex(){
		List<StockIndex> stIndices = new ArrayList<StockIndex>();
		Session s = HibernateUtil.currentSession();
		Query qr;
		qr = s.createQuery("from BaseStockIndex ");
		stIndices = qr.list();
		HibernateUtil.closeSession();
		return stIndices;
	}
	public static StockIndex getStockIndex(String stIndexId){
		StockIndex stIndex;
		Session s = HibernateUtil.currentSession();
		Query qr;
		qr = s.createQuery("from BaseStockIndex a where a.stockIndexId =:param");
		qr.setParameter("param", stIndexId);
		stIndex = (StockIndex)qr.uniqueResult();
//		HibernateUtil.closeSession();
		return stIndex;
	}
	
	
	
	public static List<StockIndex> getStockIndex(FnCalendar baseDate){
		List<StockIndex> stIndices = new ArrayList<StockIndex>();
		Session s = HibernateUtil.currentSession();
		s.enableFilter("dateFilter").setParameter("asOfDate", baseDate);
		Query qr;
		qr = s.createQuery("from BaseStockIndex ");
		stIndices = qr.list();
//		HibernateUtil.closeSession();
		return stIndices;
	}
	
	public static StockIndex getStockIndex(String stockIndexId, FnCalendar baseDate){
		StockIndex stIndex;
		Session s = HibernateUtil.currentSession();
		s.enableFilter("dateFilter").setParameter("asOfDate", baseDate);
		Query qr;
		qr = s.createQuery("from BaseStockIndex a where a.stockIndexId =:param");
		qr.setParameter("param", stockIndexId);
		stIndex = (StockIndex)qr.uniqueResult();
//		HibernateUtil.closeSession();
		return stIndex;
	}
	
	
//	public static IrCurve getSceIrCurve(String ircId, FnCalendar baseDate, String sceId){
//		IrCurve ir;
//		Session s = HibernateUtil.currentSession();
//		s.enableFilter("dateFilter").setParameter("asOfDate", baseDate);
//		Query qr;
//		qr = s.createQuery("from SceIrCurve a where a.ircId =:param");
//		qr.setParameter("param", ircId);
//		ir = (IrCurve)qr.uniqueResult();
////		HibernateUtil.closeSession();
//		return ir;
//		return ir;
//	}
}
